package com.qf.medicaldoctoradmin.onlineSigning.TeamHomepage.service.Impl;

import com.qf.common.entity.Doctor;
import com.qf.common.entity.User;
import com.qf.common.utils.DateUtils;
import com.qf.common.utils.RedisUtils;
import com.qf.medicaldoctoradmin.onlineSigning.TeamHomepage.dao.DoctorDao;
import com.qf.medicaldoctoradmin.onlineSigning.TeamHomepage.dao.DoctorSignDAO;
import com.qf.medicaldoctoradmin.onlineSigning.TeamHomepage.dao.TeamHomepageDao;
import com.qf.medicaldoctoradmin.onlineSigning.TeamHomepage.service.DoctorService;
import com.qf.medicaldoctoradmin.onlineSigning.TeamHomepage.vo.TeamHomepageVo;
import com.qf.medicaldoctoradmin.user.dao.UserDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Resource
    private DoctorDao doctorDao;

    @Resource
    private UserDao userDao;

    @Resource
    private TeamHomepageDao teamHomepageDao;

    @Resource
    private DoctorSignDAO doctorSignDAO;


    @Override
    public Doctor selectById(Integer id) {
        return doctorDao.selectById(id);
    }
    @Override
    public void DoctorByIdSign(Integer id,Integer uid) {

        String doctorId = id.toString();
        String userId = uid.toString();
        String key = "doctor:"+id + ":signups";
        String userKey = "user:"+uid + ":doctor:"+id;
        //检查医生是否已满额
        long signupCount = RedisUtils.getDoctorSignupCount(id.toString());
        if (signupCount >= 10) {
            throw new RuntimeException("该医生已经签满了,暂时无法签约");
        }

        RedisUtils.trySignUpDoctor(doctorId,userId);
    }

    @Override
    public List<TeamHomepageVo> SignTeamDoctorAll() {
        return teamHomepageDao.selectTeamHomepageAll(0);
    }
}
